package day240222;

public class BubbleSort {
    public static void main(String[] args) {
        // 待排序的数据
        System.out.println("待排序的数组");
        int[] arr = new int[]{28, 5, 11, 9, 2};

        //代码
        //排序前
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();

        for (int j = 0; j < arr.length - 1; j++) {
            for (int i = 0; i < arr.length - 1; i++) {
                if (arr[i] > arr[i+1]){
                    int t = arr[i];
                    arr[i] = arr [i+1];
                    arr[i+1] = t;
                }
            }
            System.out.println("第" + (j+1) + "轮排序后数组");
            for (int k = 0; k < arr.length; k++) {
                System.out.print(arr[k] + " ");
            }
            System.out.println();
        }

//        排序后
//        System.out.println("排序后的数组");
//        for (int i = 0; i < arr.length; i++) {
//            System.out.print(arr[i] + " ");
//        }
    }
}
